

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>设置我的资料</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <!--引入本地的css样式-->
  <link rel="stylesheet" href="../../../static/layui/css/layui.css" media="all">
  <!--<link rel="stylesheet" href="../../../static/css/admin.css" media="all">-->

</head>
<body>

<!--<button type="button" class="layui-btn layui-btn-danger" id="test7"><i class="layui-icon"></i>上传图片</button>-->

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">设置我的资料</div>

            <div class="layui-form" lay-filter="myform">

              <div class="layui-form-item">
                <label class="layui-form-label">用户名称</label>
                <div class="layui-input-inline">
                  <!--显示用户名称：但是显示的input被禁用了，所以待会儿提交表单无法带参数，所以还得搞一个隐藏域来传递-->
                  <input type="text" name="username"  readonly disabled class="layui-input layui-disabled">
                  <!--影藏域-->
                  <input type="hidden" name="username"  class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                  <input type="radio" name="sex" value="1" title="男">
                  <input type="radio" name="sex" value="2" title="女">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">联系方式</label>
                <div class="layui-input-inline">
                  <input type="text" name="tel" lay-verify="tel" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">邮箱地址</label>
                <div class="layui-input-inline">
                  <input type="text" name="email"  lay-verify="email" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">用户头像</label>
                <div class="layui-input-inline">
                  <input name="user_picture" lay-verify="required" id="LAY_avatarSrc" placeholder="图片地址" class="layui-input">
                </div>
                <div class="layui-upload">
                  <button type="button" class="layui-btn" id="test1">上传图片</button>
                  <div class="layui-upload-list">
                    <img class="layui-upload-img" id="demo1">
                    <p id="demoText"></p>
                  </div>
                  <div style="width: 95px;">
                    <div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="demo">
                      <div class="layui-progress-bar" lay-percent=""></div>
                    </div>
                  </div>
                </div>
              </div>

              <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn" lay-submit lay-filter="setmyinfo">确认修改</button>
                  <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
                </div>
              </div>
            </div>
            
          </div>
        </div>
      </div>
    </div>
  </div>

  <script type="text/javascript" src="../../../static/js/jquery-3.6.0.min.js"></script>
  <!--引入本地layui.js-->
  <script src="../../../static/layui/layui.js"></script>

  <script type="text/javascript">
      layui.use(['form', 'layedit', 'laydate','upload','element'], function() {
          var form = layui.form
              , layer = layui.layer
              ,upload = layui.upload
              ,element = layui.element
              , layedit = layui.layedit
              , laydate = layui.laydate;

          //json字符串
          var obj = sessionStorage.getItem("user");
          if(obj != null){
              //将json字符串转换为普通js对象，目的：js对象，可以直接打点调用取值
              var user = JSON.parse(obj);
              //页面加载，就应该去sessionStorage获取登录成功账户的信息，塞入到对应编辑输入框
              form.val('myform', {
                  "username": user.username // "name": "value"
                  ,"sex": user.sex
                  ,"tel": user.tel
                  ,"email": user.email
                  ,"user_picture": user.user_picture
              });
          }


      });
  </script>

  <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
  <script>
      layui.use(['upload', 'element', 'layer'], function(){
          var $ = layui.jquery
              ,upload = layui.upload
              ,element = layui.element
              ,layer = layui.layer;

          //常规使用 - 普通图片上传
          var uploadInst = upload.render({
              elem: '#test1'
              ,url: '/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
              ,before: function(obj){
                  //预读本地文件示例，不支持ie8
                  obj.preview(function(index, file, result){
                      $('#demo1').attr('src', result); //图片链接（base64）
                  });

                  element.progress('demo', '0%'); //进度条复位
                  layer.msg('上传中', {icon: 16, time: 0});
              }
              ,done: function(res){
                  //如果上传失败
                  if(res.code > 0){
                      return layer.msg('上传失败');
                  }
                  //上传成功的一些操作
                  //……
                  $('#demoText').html(''); //置空上传失败的状态
              }
              ,error: function(){
                  //演示失败状态，并实现重传
                  var demoText = $('#demoText');
                  demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                  demoText.find('.demo-reload').on('click', function(){
                      uploadInst.upload();
                  });
              }
              //进度条
              ,progress: function(n, elem, e){
                  element.progress('demo', n + '%'); //可配合 layui 进度条元素使用
                  if(n == 100){
                      layer.msg('上传完毕', {icon: 1});
                  }
              }
          });







      });
  </script>


</body>
</html>